<?php
require_once "framework/config.php";

class Redirect
{
    var $queryString = '';

    function Redirect ( $queryString = '' )
    { 
        $this->queryString = $queryString;
    }
    
    function start()
    {
        if( !$this->isRedirect() )
        {
            return false;
        }
        
        $this->go();
        return false;
    }

    function go()
    {
        $options = &PEAR::getStaticProperty('CONFIG_INI','GLOBAL');
        $url = '';

        if (  $this-> getCodeId() != '' )
        {
            $url = rtrim($options['service_url'],'/')."/?cmd=HuntCode&code=".$this-> getCodeId();            
        }
        else
        {
            return false;
        }

        trigger_error("LEAVE Redirect::go() ".$url, E_USER_NOTICE);

        header("Location: ".$url);
        exit;
    }

    function isRedirect()
    {

        if ( $this->queryString == '' )
        {
            return false;
        }

        if( preg_match("/\w+/i", $this->queryString) )
        {
            return true;
        }

        return false;
    }

    function getCodeId()
    {
        return $this->queryString ;
    }

}

$go = isset($_GET["c"]) ? $_GET["c"] : null;
$r = new Redirect( $go );
$r -> start();
?>
